/**
 * @author EasonChan
 *
 * Nov 17, 2010
 */
package com.musicgeek.biz.user;

import java.util.Map;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import com.musicgeek.dao.User;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class Logout extends ActionSupport {
	private static final long serialVersionUID = 2300279804495791997L;

	@Override
	public String execute() {
		HttpServletResponse response = ServletActionContext.getResponse();
		Cookie[] cookies = ServletActionContext.getRequest().getCookies();
		// Delete cookies.
		for (Cookie cookie : cookies) {
			cookie.setMaxAge(0);
			cookie.setPath("/");
			response.addCookie(cookie);
		}
		Map<String, Object> session = ActionContext.getContext().getSession();
		session.remove(User.USER);
		return SUCCESS;
	}
}
